package com.buba.service.impl;

import com.buba.dao.LogoMapper;
import com.buba.service.LogoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LogoServiceImpl implements LogoService {
    @Autowired
    private LogoMapper logoMapper;

    @Override
    public Map<String, List<String>> selLoginLogChart(String s) {
        List<Map<String, Object>> list = logoMapper.selLoginLogChart(s);
        // 查询结果是Date类型，需要格式化
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, List<String>> resultMap = new HashMap<>();
        List<String> dateList = new ArrayList<>();
        List<String> countList = new ArrayList<>();
        for (Map<String, Object> map : list) {
            dateList.add(dateFormat.format(map.get("date")));
            countList.add(map.get("count") + "");
        }
        resultMap.put("dateList", dateList);
        resultMap.put("countList", countList);
        return resultMap;
    }
}
